<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use GuzzleHttp\Client;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\exception\ValidateException;

/**
 * 年级
 *
 * Class Grade
 * @package app\admin\controller
 */
class Grade extends Backend
{
    /**
     * @var \app\common\model\Grade
     */
    protected $model = null;
    protected $searchFields = 'name';
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('Grade');
    }

    public function searchlist()
    {
        $result = $this->model->all();

        $searchList = [];
        foreach ($result as $key => $value) {
            $searchList[] = ['id' => $value['id'], 'name' => $value['name']];
        }
        $data = ['searchlist' => $searchList];
        $this->success('', null, $data);
    }

    /**
     * 联动搜索
     */
    public function cxSelect()
    {
        $result = $this->model->all();

        $searchList = [];
        foreach ($result as $key => $value) {
            $searchList[] = ['value' => $value['id'], 'name' => $value['name']];
        }

        $this->success('', null, $searchList);
    }

    public function selectpage()
    {
        return parent::selectpage();
    }
}
